from django.db import models

# Create your models here.

# 会员模型
class Users(models.Model):
    # 用户名
    username = models.CharField(max_length = 32)
    # 邮箱
    email = models.CharField(max_length = 50,null=True)
    # 手机号
    phone = models.CharField(max_length = 11)
    # 密码
    password = models.CharField(max_length = 80)
    # 年龄
    age = models.IntegerField(null=True)
    # 性别
    sex = models.CharField(max_length=1,default='0')
    # 头像
    pic = models.CharField(max_length=100,default='1.jpg')
    # 状态 0 正常  1禁用
    isDelete = models.BooleanField(default=False)
    # 注册时间
    addtime = models.DateTimeField(auto_now_add=True)

# 商品分类模型
class Types(models.Model):
    name = models.CharField(max_length=10)
    pid = models.IntegerField()
    path = models.CharField(max_length=20)


# 商品模型
class Goods(models.Model):
    tid = models.ForeignKey(to="Types", to_field="id")
    title = models.CharField(max_length=125)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    store = models.IntegerField()
    info = models.TextField()
    pic = models.CharField(max_length=100)
    clicknum = models.IntegerField(default=0)
    ordernum = models.IntegerField(default=0)
    # 1 新发布  2 热卖  0缺货
    status = models.IntegerField(default=1)
    isDelete = models.BooleanField(default=False)
    addtime = models.DateTimeField(auto_now_add=True)




# 购物车模型
class Cart(models.Model):
    uid = models.ForeignKey(to='Users',to_field='id')
    gid = models.ForeignKey(to='Goods',to_field='id')
    num = models.IntegerField()
    addtime = models.DateTimeField(auto_now_add=True)

# 收货地址模型
class Address(models.Model):
    uid = models.ForeignKey(to='Users',to_field='id')
    name = models.CharField(max_length=10)
    phone = models.CharField(max_length=11)
    address = models.CharField(max_length=50)
    isSelect = models.BooleanField(default=False)


# 订单模型
class Order(models.Model):
    uid = models.ForeignKey(to='Users',to_field='id')
    addressid = models.ForeignKey(to='Address',to_field='id')
    totalprice = models.FloatField()
    # 0已取消 1 未支付 2 已支付,待发货  3 已发货,待收货  4 以收货 待评价
    status = models.IntegerField()
    addtime = models.DateTimeField(auto_now_add=True)


# 订单详情
class OrderInfo(models.Model):
    orderid = models.ForeignKey(to='Order',to_field='id')
    goodsid = models.ForeignKey(to='Goods',to_field='id')
    num = models.IntegerField()
    price = models.FloatField()
